package com.sgzn.sgpay.web.controller;

import com.sgzn.sgpay.model.request.SgsIncreaseCreditQueryPageRequest;
import com.sgzn.sgpay.model.request.util.PageQueryParam;
import com.sgzn.sgpay.model.response.SgsResultResponse;
import com.sgzn.sgpay.model.response.result.MainOrderQueryPageResult;
import com.sgzn.sgpay.service.SgsIncreaseCreditQueryService;
import com.sgzn.sgpay.web.controller.base.UserBaseController;
import com.sgzn.sgpay.web.handle.AssembleCommonHandle;
import com.sgzn.sgpay.web.request.Impl.IncreaseCreditQueryPageRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 游戏记录（上分记录）查询控制器
 * @author huangsenguang
 * @version Id: IncreaseCreditQueryController.java, v 0.1 2018/5/6 14:20 huangsenguang Exp $$
 */
@Slf4j
@Controller
@RequestMapping("/user")
public class IncreaseCreditQueryController extends UserBaseController{
    @Autowired
    private SgsIncreaseCreditQueryService sgsIncreaseCreditQueryService;
    @Resource
    private AssembleCommonHandle assembleCommonHandle;

    /**
     * 游戏记录（上分记录）分页查询
     * @param request
     * @return
     */
    @RequestMapping("/increaseCreditRecord/queryPage")
    @ResponseBody
    public SgsResultResponse<MainOrderQueryPageResult> queryPageMainOrder(IncreaseCreditQueryPageRequest request) {
        super.setUserInfo(request);
        return this.sgsIncreaseCreditQueryService.queryPage(assembleQueryPageRequest(request));
    }

    /**
     * 组装服务请求
     * @param request
     * @return
     */
    private SgsIncreaseCreditQueryPageRequest assembleQueryPageRequest(IncreaseCreditQueryPageRequest request) {
        SgsIncreaseCreditQueryPageRequest sgsIncreaseCreditQueryPageRequest = new SgsIncreaseCreditQueryPageRequest();
        this.assembleCommonHandle.assembleUserRequest(request, sgsIncreaseCreditQueryPageRequest);
        PageQueryParam pageQueryParam = new PageQueryParam();
        pageQueryParam.setPageSize(Integer.parseInt(request.getPageSize()));
        pageQueryParam.setCurrentPage(Integer.parseInt(request.getPageNum()));
        sgsIncreaseCreditQueryPageRequest.setPageQueryParam(pageQueryParam);
        return sgsIncreaseCreditQueryPageRequest;
    }
}

